import { request } from '../request';

/** ************* user *********** */
export function fetchEditUser(data: Api.SystemManage.UserEdit) {
  return request<boolean>({
    url: '/sys/user/edit',
    method: 'post',
    data
  });
}
export function fetchSaveUser(data: Api.SystemManage.UserEdit) {
  return request<boolean>({
    url: '/sys/user/save',
    method: 'post',
    data
  });
}
export function fetchGetUserList(params?: Api.SystemManage.UserSearchParams) {
  return request<Api.SystemManage.UserList>({
    url: '/sys/user/query',
    method: 'post',
    params
  });
}
export function fetchDelUserById(id: number) {
  return request<boolean>({
    url: `/sys/user/del/${id}`,
    method: 'get'
  });
}

/** ************* role *********** */
export function fetchGetAllRoles() {
  return request<Api.SystemManage.Role[]>({
    url: '/sys/role/getAllRoles',
    method: 'get'
  });
}
/** get role list */
export function fetchGetRoleList(params?: Api.SystemManage.RoleSearchParams) {
  return request<Api.SystemManage.RoleList>({
    url: '/sys/role/query',
    method: 'post',
    params
  });
}
export function fetchSaveRole(data: Api.SystemManage.RoleEdit) {
  return request<boolean>({
    url: '/sys/role/save',
    method: 'post',
    data
  });
}
export function fetchEditRole(data: Api.SystemManage.RoleEdit) {
  return request<boolean>({
    url: '/sys/role/edit',
    method: 'post',
    data
  });
}
export function fetchDelRole(id?: number) {
  return request<boolean>({
    url: `/sys/role/del/${id}`,
    method: 'get'
  });
}

export function fetchGetRoleCheckedMenuIds(id: string) {
  return request<string[]>({
    url: `/sys/role/menuIds/${id}`,
    method: 'get'
  });
}
export function fetchGetRoleMenuCheckedButtons(id: string) {
  return request<string[]>({
    url: `/sys/role/menuIds/${id}`,
    method: 'get'
  });
}
export function fetchGetCurrentUserRoleMenuButtons() {
  return request<Api.SystemManage.RoleMenuButton[]>({
    url: `/sys/role/menu/buttons`,
    method: 'get'
  });
}
export function fetchGetRoleSelectedMenuButtons(id: string) {
  return request<string[]>({
    url: `/sys/role/menu/buttons/checked/${id}`,
    method: 'get'
  });
}
export function fetchSaveRoleMenuButtons(data: Api.SystemManage.RoleMenuButtonPermission) {
  return request<boolean>({
    url: '/sys/role/menu/buttons/save',
    method: 'post',
    data
  });
}
export function fetchSaveRoleMenuIds(data: Api.SystemManage.RoleMenu) {
  return request<boolean>({
    url: '/sys/role/save/menuIds',
    method: 'post',
    data
  });
}

/**
 * get all roles
 *
 * these roles are all enabled
 */
// export function fetchGetAllRoles() {
//   return request<Api.SystemManage.AllRole[]>({
//     url: '/systemManage/getAllRoles',
//     method: 'get'
//   });
// }

/** get user list */
// export function fetchGetUserList(params?: Api.SystemManage.UserSearchParams) {
//   return request<Api.SystemManage.UserList>({
//     url: '/systemManage/getUserList',
//     method: 'get',
//     params
//   });
// }

/** save menu */
export function fetchSaveMenu(data: Api.SystemManage.MenuEdit) {
  return request<boolean>({
    url: '/sys/menu/save',
    method: 'post',
    data
  });
}
/** update menu */
export function fetchEditMenu(data: Api.SystemManage.MenuEdit) {
  return request<boolean>({
    url: '/sys/menu/edit',
    method: 'post',
    data
  });
}

export function fetchDelMenu(data: Api.Common.Delete) {
  return request<boolean>({
    url: '/sys/menu/del',
    method: 'post',
    data
  });
}

/** get menu list */
export function fetchGetMenuList(params?: Api.Common.QueryPageParams) {
  return request<Api.SystemManage.MenuList>({
    url: '/sys/menu/query',
    method: 'post',
    params
  });
}

/** get all pages */
export function fetchGetAllPages() {
  return request<string[]>({
    url: '/sys/menu/getAllPages',
    method: 'get'
  });
}

/** get menu tree */
export function fetchGetMenuTree() {
  return request<Api.SystemManage.Menu[]>({
    url: '/sys/menu/getAllTree',
    method: 'get'
  });
}
